package cn.tj212.xiaoyin.core.auth.service.impl;

import cn.tj212.xiaoyin.common.page.TailPage;
import cn.tj212.xiaoyin.common.storage.QiniuStorage;
import cn.tj212.xiaoyin.core.auth.dao.AuthUserDao;
import cn.tj212.xiaoyin.core.auth.domain.AuthUser;
import cn.tj212.xiaoyin.core.auth.service.IAuthUserService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AuthUserServiceImpl implements IAuthUserService {

    @Autowired
    private AuthUserDao entityDao;

    @Override
    public AuthUser getByUsernameAndPassword(AuthUser authUser) {
        return entityDao.getByUsernameAndPassword(authUser);
    }

    /**
     * 首页5个推荐讲师
     * @return
     */
    @Override
    public List<AuthUser> queryRecomd() {
        List<AuthUser> recomdList=entityDao.queryRecomd();
        if (CollectionUtils.isNotEmpty(recomdList)){
            for (AuthUser item:recomdList
                 ) {
                if (StringUtils.isNotEmpty(item.getHeader())){
                    item.setHeader(QiniuStorage.getUrl(item.getHeader()));
                }
            }
        }
        return recomdList;
    }

    @Override
    public TailPage<AuthUser> queryPage(AuthUser queryEntity, TailPage<AuthUser> page) {
        Integer itemsTotalCount=entityDao.getTotalItemsCount(queryEntity);
        List<AuthUser> items=entityDao.queryPage(queryEntity,page);
        page.setItemsTotalCount(itemsTotalCount);
        page.setItems(items);
        return page;
    }

    @Override
    public void update(AuthUser entity) {
        entityDao.update(entity);
    }

    @Override
    public void updateSelectivity(AuthUser entity) {
        entityDao.updateSelectivity(entity);
    }

    @Override
    public void delete(AuthUser entity) {
        entityDao.delete(entity);
    }

    @Override
    public void deleteLogic(AuthUser entity) {
        entityDao.deleteLogic(entity);
    }

    @Override
    public AuthUser getByUsername(String username) {
        return entityDao.getByUsername(username);
    }

    @Override
    public AuthUser getById(Long userId) {
        return entityDao.getById(userId);
    }

    @Override
    public AuthUser createSelectivity(AuthUser entity) {
        return entityDao.createSelectivity(entity);
    }
}
